/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package components;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

/**
 *
 * @author Memet
 */
public class JPictureBox extends javax.swing.JPanel {

    BufferedImage picture;

    /** Creates new form JPictureBox */
    public JPictureBox() {
        initComponents();
        picture = null;
    }

    public BufferedImage getPicture()
    {
        return picture;
    }

    public void setPicture(BufferedImage picture)
    {
        this.setSize(picture.getWidth(this), picture.getHeight(this));
        this.picture=picture;
        this.revalidate();
        this.repaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 151, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 124, Short.MAX_VALUE)
        );
    }// </editor-fold>                        

    @Override
    public void paint(Graphics g)
    {
        super.paint(g);
        Graphics2D g2 = (Graphics2D) g;
        g2.drawImage(picture, 0, 0, this.getWidth(), this.getHeight(), this);
    }

    // Variables declaration - do not modify                     
    // End of variables declaration                   

}